
# -*- coding: utf-8 -*-

from django.db import models
from django.utils.encoding import force_unicode
import unicodedata

class CargoAcademico(models.Model):
    Cargo = models.CharField(max_length=200, verbose_name="* Nombre", unique=True)
    Descripcion_cargo = models.TextField(blank=True, verbose_name="Descripción") 
    Imagen = models.ImageField(max_length=300,upload_to='media/CargosA',blank=True,null=True, default="static/images/default.png", verbose_name="Logo")
    Jerarquia = models.IntegerField(verbose_name="* Jerarquía", blank=False, null=False, help_text='Debe ser un número entero')

    def save(self, **args):
        for field in self._meta.fields:
            if field.name == 'Imagen':
                field.upload_to = 'media/CargosA/%s' % unicodedata.normalize('NFKD', self.Cargo).encode('ascii','ignore').replace(" ", "")
        super(CargoAcademico, self).save()
    
    class Meta:
        db_table = 'CargoAcademico' 
        ordering = ['Jerarquia','Cargo']
        verbose_name = "Cargo"
        
       
    def __str__(self):
        return force_unicode(self.Cargo)

    def __unicode__(self):
        return force_unicode(self.Cargo)
